/**
  ************************************* Copyright ******************************
  * FileName   : screen.h
  * Version    : v1.0
  * Author     : yychao
  * Date       : 2023-06-16
  * Description:
  * Function List:
  	1. ....
  	   <version>:
  <modify staff>:
  		  <data>:
   <description>:
  	2. ...
  ******************************************************************************
 */

#ifndef __SCREEN_H_
#define __SCREEN_H_

#include "usart.h"

#define P_CONNECT				(0)
#define P_INITIAL				(1)
#define P_KEYBOARD				(2)
#define P_MAIN					(3)
#define P_MENU					(4)
#define P_TIME					(5)
#define P_CURVE					(6)
#define P_BURN					(7)
#define P_CTRL					(8)
/***********************************************************/
/*page main*/
#define T_MAIN_2_MENU		(0x9000)
#define T_MAIN_2_CTRL		(0x9001)
#define DIS_MAIN_AIM_DRY	(0x6000)
#define DIS_MAIN_AIM_WET	(0x6001)
#define DIS_MAIN_UP_DRY		(0x6002)
#define DIS_MAIN_UP_WET		(0x6003)
#define DIS_MAIN_DN_DRY		(0x6004)
#define DIS_MAIN_DN_WET		(0x6005)
#define DIS_MAIN_STAGE		(0x6006)
#define DIS_MAIN_PAST		(0x6007)
#define DIS_MAIN_PAST_ALL	(0x6008)
/*page menu*/
#define T_MENU_2_MAIN		(0x9010)
#define T_MENU_2_TIME		(0x9011)
#define T_MENU_2_CURVE		(0x9012)
#define T_MENU_2_BK			(0x9013)
/*page time*/
#define T_TIME_2_MENU		(0x9020)
#define T_TIME_SAVE			(0x9021)
#define TD_TIME_YEAR		(0x6020)
#define TD_TIME_MONTH		(0x6021)
#define TD_TIME_DATE		(0x6022)
#define TD_TIME_HOUR		(0x6023)
#define TD_TIME_MINUTE		(0x6024)
#define TD_TIME_SECOND		(0x6025)
#define TD_TIME_WEEK		(0x6026)
/*page curve*/
#define T_CURVE_2_MENU		(0x9030)
#define T_CURVE_SAVE		(0x9031)

#define TD_CURVE_DRY1		(0x6030)
#define TD_CURVE_DRY2		(0x6031)
#define TD_CURVE_DRY3		(0x6032)
#define TD_CURVE_DRY4		(0x6033)
#define TD_CURVE_DRY5		(0x6034)
#define TD_CURVE_DRY6		(0x6035)
#define TD_CURVE_DRY7		(0x6036)
#define TD_CURVE_DRY8		(0x6037)
#define TD_CURVE_DRY9		(0x6038)
#define TD_CURVE_DRY10		(0x6039)

#define TD_CURVE_WET1		(0x6040)
#define TD_CURVE_WET2		(0x6041)
#define TD_CURVE_WET3		(0x6042)
#define TD_CURVE_WET4		(0x6043)
#define TD_CURVE_WET5		(0x6044)
#define TD_CURVE_WET6		(0x6045)
#define TD_CURVE_WET7		(0x6046)
#define TD_CURVE_WET8		(0x6047)
#define TD_CURVE_WET9		(0x6048)
#define TD_CURVE_WET10		(0x6049)

#define TD_CURVE_UP1		(0x6050)
#define TD_CURVE_UP2		(0x6051)
#define TD_CURVE_UP3		(0x6052)
#define TD_CURVE_UP4		(0x6053)
#define TD_CURVE_UP5		(0x6054)
#define TD_CURVE_UP6		(0x6055)
#define TD_CURVE_UP7		(0x6056)
#define TD_CURVE_UP8		(0x6057)
#define TD_CURVE_UP9		(0x6058)
#define TD_CURVE_UP10		(0x6059)

#define TD_CURVE_STD1		(0x6060)
#define TD_CURVE_STD2		(0x6061)
#define TD_CURVE_STD3		(0x6062)
#define TD_CURVE_STD4		(0x6063)
#define TD_CURVE_STD5		(0x6064)
#define TD_CURVE_STD6		(0x6065)
#define TD_CURVE_STD7		(0x6066)
#define TD_CURVE_STD8		(0x6067)
#define TD_CURVE_STD9		(0x6068)
#define TD_CURVE_STD10		(0x6069)
/*page bk*/
#define T_BK_2_MENU		(0x9040)
#define T_BK_SAVE			(0x9041)
/*page ctrl*/
#define T_CTRL_2_MAIN		(0x9050)

#define T_CTRL_BAKE			(0x9052)
#define T_CTRL_FIRE			(0x9053)
#define T_CTRL_FEED			(0x9054)
#define T_CTRL_BFAN			(0x9055)
#define T_CTRL_CYCLE		(0x9056)
#define T_CTRL_AIR			(0x9057)
#define T_CTRL_CLEAR		(0x9058)
#define T_CTRL_INI			(0x9059)

#define T_CTRL_SAVE1		(0x9060)
#define T_CTRL_SAVE2		(0x9062)

#define P_CTRL_BAKE			(0x5050)
#define P_CTRL_FIRE			(0x5051)
#define P_CTRL_FEED			(0x5052)
#define P_CTRL_BFAN			(0x5053)
#define P_CTRL_CYCLE		(0x5054)
#define P_CTRL_AIR			(0x5055)
#define P_CTRL_CLEAR		(0x5056)

#define TD_CTRL_BFAN		(0x6080)
#define TD_CTRL_CYCLE		(0x6081)
#define TD_CTRL_AIR			(0x6082)
#define TD_CTRL_CLEAR		(0x6083)

/***********************************************************/
#define OK				(0)
#define FAILED			(1)

#define PIC_ON			(2)
#define PIC_OFF			(1)
/***********************************************************/
extern const uint8_t chk_array[6];
#define PROT_HEAD 0x5AA5
typedef enum {
    Read = 0x83, Write = 0x82, Touch = 0x83,
} prot_cmd;
typedef enum {
    head_err = 0, len_err, cmd_err, crc_err
} prot_err;


struct protocol {
    uint16_t head;
    uint8_t len;
    prot_cmd cmd;
    uint16_t crc;
    uint8_t err_code;

    uint16_t addr;
    uint8_t byte;
    uint16_t value_16;
    uint16_t value_32;

    uint16_t rsp_addr;
    uint16_t rsp_value;
    uint8_t RspCode;
};
extern struct protocol screen_prot;

#define SCREEN_MQ_BUF_SIZE		128
#define SCREEN_TX_BUF_SIZE		128
struct screen_para {
    uint8_t trans_data[SCREEN_TX_BUF_SIZE];
    uint16_t trans_len;
    uint8_t wanter_flag;
    uint8_t wanter_data[128];
    uint32_t ms;
};
extern struct screen_para screen_para_st;

struct screen_time {
    uint16_t Year;
    uint16_t Month;
    uint16_t Date;
    uint16_t Week;

    uint16_t Hour;
    uint16_t Minute;
    uint16_t Second;
};
extern struct screen_time screen_time_st;

struct screen_curve {
    uint16_t dry[10];
    uint16_t wet[10];
    uint16_t up[10];
    uint16_t std[10];
};
extern struct screen_curve screen_curve_st;

struct screen_bakectrl {
    uint16_t value[10];
};
extern struct screen_bakectrl screen_bakectrl_st;

void screen_deal(usart_cache* recv);
void screen_adv(uint8_t *data, uint16_t len);
void screen_frame(uint8_t *data, uint16_t len);
void Screen_OutQueue(void);
uint8_t screen_touch(uint8_t *data, uint16_t len);
uint8_t screen_write(uint16_t addr, uint16_t *value, uint16_t num);
uint8_t screen_data_check(struct screen_para* st);
uint8_t screen_page(uint16_t page);
uint8_t screen_ini(void);
#endif


